clear all;clc
addpath(genpath('.'));
load pix_location
load Point_Set
load Scale
load SID
load p_xid p_xid
load p_yid p_yid
Stego=rgb2ycbcr(imread('./Ext_exp/Fang/image1/A30_6.jpg'));
% Stego=(imread('./Watermark_exp/image9/Aloc_2.jpg'));%画图用下彩色的
% Y_Stego_O=Stego;
Y_Stego_A=Stego(:,:,1);
Y_Stego=imresize(Y_Stego_A,Scale(SID(p_xid)));
%% Point_Set 四点确定的IoU区域
% 逆变换找对应尺度下的坐标
pix_location([3 2],:)=pix_location([2 3],:);
pix_location(:,[2 1])=pix_location(:,[1 2]);
Correction_Stego=registerImages(Y_Stego,pix_location);
Correction_Stego=imresize(Correction_Stego,[1408,2432]);
Extract_Stego=imcrop(Correction_Stego,[64,64,size(Correction_Stego,2)-128,size(Correction_Stego,1)-128]);
%% 水印提取，zhang_scheme
% Extract_Stego=Y_Stego_A;
% [row,col]=size(Extract_Stego);
% block_size=min(row,col);
% Extract_Stego=Extract_Stego-wiener2(Extract_Stego);
% minber=[];
nc=[];
% load WZ
% load g
% for J=1:round((col/20)):col %列滑窗
%        ZOOM_Block=Extract_Stego(1:block_size,(J:J-1+block_size));
%        [DFT_Cover,P]=InputProc(ZOOM_Block);%取幅值谱
% %        imshow(log(1+DFT_Cover),[])
% %        [R(I,J),V(I,J)]=Ext_alg(DFT_Cover);
% %         msg=repmat([1,0],1,32);
% %         ZOOM_Block=imresize(ZOOM_Block,[1280,1280]);  
%         [fudu_matr,fudu_cnt,position_matr,mean_fudu_matr,result_3,C,mean_fudu_g,result_corr,x_offset_ture,y_offset_ture,flag_555,data_1,data_2,data_corr,index_num,margin0,size_return,state]=Linextract(ZOOM_Block,WZ,g);
%         rand('state',5);%要嵌入的水印矩阵
%         water_img=round(rand(10,10));
%         if isempty(result_3)==0
%             disp(1-sum(sum(abs(water_img-result_3)))/100);
%             nc=[nc,1-sum(sum(abs(water_img-result_3)))/100];
%         end
% %         minber=[minber,Zhangext(DFT_Cover,msg)];
%         if col-J-round((col/20))-block_size<0
%             break;
%         end 
% end
load W
%水印提取 Fang Scheme
[imgw2,WG]=Extracting_test(Extract_Stego);
imgw = reshape(imgw2,[1,64]);
nc=1-sum(sum(abs(double(W)-imgw2)))/64;
disp(['Fang_NC:',num2str(nc)]);
% disp(1-min(minber)/64);
% imwrite(Extract_Stego,'./Watermark_exp/abc.png');
%% 阈值化提取水印
% Bit_Stream=[Bit_Stream,bit];

%% 生成原始比特，计算Ber
% load key
% load p
% rng(key); %%key为伪随机序列种子
% msg = num2str(uint8(rand(1,100*100)));
% msg=strrep(msg,' ','');%剔除空格
% embed_msg=msg(1:p-1);%获取嵌入的秘密信息
% embed_msg=mychar2double(embed_msg);